home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / Marching Ants Library / MarchingAnts.h < prev   
Encoding:
Text File  |  1994-07-12  |  6.8 KB  |  152 lines  |  [TEXT/MPCC]

  1. //=====================================================================================
  2. // MarchingAnts.h -- written by Aaron Giles
  3. // Last update: 7/7/94 (version 1.1)
  4. //=====================================================================================
  5. // A source code library for handling rectangular graphical selections involving the
  6. // famous "marching ants".  This header file contains a brief description of each
  7. // function; see the prelude to each function in the definition file MarchingAnts.c
  8. // for a full description of its operation and expected use.
  9. //=====================================================================================
  10. // This code has been compiled successfully under MPW C, MPW PPCC, THINK C, and
  11. // Metrowerks C/C++, both 68k and PowerPC.  This code has been compiled under both the
  12. // Universal Headers and the old 7.1 headers; if it works earlier than that I cannot
  13. // say for sure.
  14. //=====================================================================================
  15. // If you find any bugs in this source code, please email me and I will attempt to fix
  16. // them.  If you have any additions/modifications that you think would be generally
  17. // useful, email those to me as well, and I will consider incorporating them into the
  18. // next release.  My email address is giles@med.cornell.edu.
  19. //=====================================================================================
  20. // This source code is copyright © 1994, Aaron Giles.  Permission to use this code in
  21. // your product is freely granted, provided that you credit me appropriately in your
  22. // application's About box/credits *and* documentation.  If you ship an application
  23. // which uses this code, I would also like to request that you provide me with one
  24. // complimentary copy of the application.
  25. //=====================================================================================
  26.  
  27. #ifndef __MARCHINGANTS__
  28. #define __MARCHINGANTS__
  29.  
  30. //=====================================================================================
  31. // Mac headers needed for the headers
  32. //=====================================================================================
  33.  
  34. #include <QDOffscreen.h>
  35.  
  36. //=====================================================================================
  37. // If you are using old headers that don't know about the new Pattern definitions you
  38. // may need to uncomment this line.
  39. //=====================================================================================
  40.  
  41. //#define dangerousPattern 1
  42.  
  43. //=====================================================================================
  44. // Definition of the AntsRecord; note that there is no need for other functions to know
  45. // anything about the internals here.  Everything that you will need is provided
  46. // through accessor functions which accept parameters of type AntsReference, which is
  47. // intended to be an opaque data type.
  48. //=====================================================================================
  49.  
  50. typedef struct AntsRecord {
  51.     GWorldPtr verticalWorld;
  52.     GWorldPtr horizontalWorld;
  53.     Rect bounds, limitRect;
  54.     GrafPtr port;
  55.     Boolean active;
  56.     Boolean visible;
  57.     Boolean drawn;
  58. } AntsRecord, *AntsPtr, **AntsHandle;
  59.  
  60. //=====================================================================================
  61. // Here is the AntsReference typedef.  All ants functions accept AntsReference
  62. // parameters instead of AntsHandles.  This makes the AntsReference a semi-opaque data
  63. // type.
  64. //=====================================================================================
  65.  
  66. typedef AntsHandle AntsReference;
  67.  
  68. //=====================================================================================
  69. // The AntsScrollProc is a callback function used for autoscrolling.  Basically it gets
  70. // called with a requested dx,dy combination, and your autoscroll function will scroll
  71. // as much as it can and return the actual amount scrolled as dx,dy.  The refCon
  72. // parameter is a user-defined long variable which can be used to store information
  73. // needed by the callback.
  74. //=====================================================================================
  75.  
  76. typedef void (*AntsScrollProc)(short *dx, short *dy, long refCon);
  77.  
  78. //=====================================================================================
  79. // Minimum values in each dimension for a "valid" selection.
  80. //=====================================================================================
  81.  
  82. enum {
  83.     antsMinimumX = 8,
  84.     antsMinimumY = 8
  85. };
  86.  
  87. //=====================================================================================
  88. // The public ants interface.
  89. //=====================================================================================
  90.  
  91. #ifdef __cplusplus
  92. extern "C" {
  93. #endif
  94.  
  95. // NewAnts: allocate and initialize a new set of ants
  96. extern AntsReference NewAnts(void);
  97.  
  98. // DisposeAnts: dispose of all memory associated with an ants record
  99. extern void DisposeAnts(AntsReference theAnts);
  100.  
  101. // AntsHaveSelection: returns true if there is a non-nil selection
  102. extern Boolean AntsHaveSelection(AntsReference theAnts);
  103.  
  104. // ResetAntsSelection: resets the selection to nil
  105. extern void ResetAntsSelection(AntsReference theAnts);
  106.  
  107. // GetAntsSelection: returns the bounding rectangle of the current selection
  108. extern void GetAntsSelection(AntsReference theAnts, Rect *theBounds);
  109.  
  110. // SetAntsSelection: change the current selection's bounding rectangle
  111. extern void SetAntsSelection(AntsReference theAnts, Rect *newBounds);
  112.  
  113. // GetAntsLimitRect: returns the limit rectangle for clipping and mouse tracking
  114. extern void GetAntsLimitRect(AntsReference theAnts, Rect *limitRect);
  115.  
  116. // SetAntsLimitRect: sets the limit rectangle for clipping and mouse tracking
  117. extern void SetAntsLimitRect(AntsReference theAnts, Rect *newLimit);
  118.  
  119. // GetAntsPort: returns the port used for drawing the ants
  120. extern GrafPtr GetAntsPort(AntsReference theAnts);
  121.  
  122. // SetAntsPort: sets the port for ant drawing
  123. extern void SetAntsPort(AntsReference theAnts, GrafPtr thePort);
  124.  
  125. // AreAntsVisible: returns true if the ants are currently being shown
  126. extern Boolean AreAntsVisible(AntsReference theAnts);
  127.  
  128. // TrackAntsSelection: tracks the mouse as a new selection is made
  129. extern void TrackAntsSelection(AntsReference theAnts, Point localStart, 
  130.             AntsScrollProc scroll, long refCon);
  131.  
  132. // ShowAnts: makes the current ants selection visible
  133. extern void ShowAnts(AntsReference theAnts);
  134.  
  135. // HideAnts: hides the current selection, restoring the original background
  136. extern void HideAnts(AntsReference theAnts);
  137.  
  138. // AnimateAnts: rotates the dashed rectangle by one notch and redraws it
  139. extern void AnimateAnts(AntsReference theAnts);
  140.  
  141. // ActivateAnts: sets up the ants so they display an animated dashed rectangle
  142. extern void ActivateAnts(AntsReference theAnts);
  143.  
  144. // DeactivateAnts: sets the ants to display a stable dotted rectangle
  145. extern void DeactivateAnts(AntsReference theAnts);
  146.  
  147. #ifdef __cplusplus
  148. }
  149. #endif
  150.  
  151. #endif
  152.